package ca;

public class NormativeComponent {
	private double[] rangeMin;
	private double[] rangeMax;
	private double[] fitnessMin;
	private double[] fitnessMax;
	private int nParameters;
	
	public NormativeComponent(int nParameters) {
		this.nParameters = nParameters;
		rangeMin = new double[nParameters];
		rangeMax = new double[nParameters];
		fitnessMin = new double[nParameters];
		fitnessMax = new double[nParameters];
	}
	
	public void setDimension(int dimension, double min, double max, double fitnessMin, double fitnessMax){
		this.rangeMin[dimension] = min;
		this.rangeMax[dimension] = max;
		this.fitnessMin[dimension] = fitnessMin;
		this.fitnessMax[dimension] = fitnessMax;
	}
	
	public void adjustSpace(double[][] individuals, double[] fitness){
		for(int k = 0; k < nParameters; k++){
			for(int i = 0; i < individuals.length; i++){
				
				if(fitness[i] < fitnessMin[k] || individuals[i][k] <= rangeMin[k]){
					rangeMin[k] = individuals[i][k];
				}
				
				if(fitness[i] < fitnessMax[k] || individuals[i][k] >= rangeMax[k]){
					rangeMin[k] = individuals[i][k];
				}
				
				if(fitness[i] < fitnessMin[k] || individuals[i][k] <= rangeMin[k]){
					fitnessMin[k] = fitness[i];
				}
				
				if(fitness[i] < fitnessMax[k] || individuals[i][k] >= rangeMax[k]){
					fitnessMax[k] = fitness[i];
				}
				
			}
		}
	}

	public double getMax(int k) {
		return this.rangeMax[k];
	}
	
	public double getMin(int k) {
		return this.rangeMin[k];
	}
}
